package com.loan.market.base

import android.app.Dialog
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.loan.market.R

abstract class BaseFragment : Fragment() {

    private lateinit var loading: Dialog

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        initUi()

        initEvent()

        initData()
    }

    abstract fun initUi()

    abstract fun initEvent()

    abstract fun initData()

    fun showLoading() {
        if (!this::loading.isInitialized) {
            loading = Dialog(requireActivity(), R.style.NormalDialog)
            loading.setContentView(R.layout.layout_progress)
            loading.setCanceledOnTouchOutside(false)
        }
        loading.show()
    }


    fun dismissLoading() {
        if (this::loading.isInitialized && loading.isShowing) {
            loading.dismiss()
        }
    }

    override fun onDestroyView() {
        super.onDestroyView()
        dismissLoading()
    }
}